• Loading packages, auto installation if needed
# creating requiredPkg function: install and load multiple R packages.
# for checking to see if required packages are installed.
# install if needed, then load into the R session.

requiredPkg <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg)) 
    install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

# applying the function
packages <- c("ggplot2", "plotly", "devtools", "colorspace", "tidyr", "plot_ly")
requiredPkg(packages)
# devtools::install_github("ropensci/plotly")
# install.packages("plotly")
# library(plotly)
# library(plot_ly)

Import data

  • Setting directory
  • Loading the dataset
#setting working directory
#(WD <- getwd())
#if (!is.null(WD)) setwd(WD)
# setwd("")
faudata <- read.table(header = TRUE, file = "feasibilityData/FAU.csv", sep = ",")
head(faudata)

fauemo <- read.table(header = TRUE, file = "feasibilityData/FAU_Emotions.csv",
                     sep = ",")
head(fauemo)

landmarks <- read.table(header = TRUE, file = "feasibilityData/Landmarks.csv",
                     sep = ",")
head(landmarks)

speech <- read.table(header = TRUE, file = "feasibilityData/Speech_Overview.csv",
                     sep = ",")
head(speech)

transcript <- read.table(header = TRUE,
                         file = "feasibilityData/Transcipt_Overview.csv",
                         sep = ",")
head(transcript)
### working with TRANSCRIPT

transcript$Emotion <- factor(transcript$Emotion) # factor
summary(transcript$Emotion)
##   Angry   Bored Excited    Fear   Happy     Sad 
##       2       9       7       2       5       5
### defining subsets
angry <- subset(transcript, transcript$Emotion=="Angry")
bored <- subset(transcript, transcript$Emotion=="Bored")
excited <- subset(transcript, transcript$Emotion=="Excited")
fear <- subset(transcript, transcript$Emotion=="Fear")
happy <- subset(transcript, transcript$Emotion=="Happy")
sad <- subset(transcript, transcript$Emotion=="Sad")
hist(transcript$Anger, xlab="ANGER")

hist(transcript$Bored, xlab="BORED")

# plot(transcript$Sr..No., transcript$Anger)

### PLOTLY graphs

f <- list(
  family = "Courier New, monospace",
  size = 18,
  color = "#7f7f7f"
)
titleFont <- list(
  family = "Courier New, monospace",
  size = 18,
  color = "#7f7f7f"
)
x <- list(
  title = "Time (instances)",
  titlefont = f
)
y <- list(
  title = "Emotion Classification",
  titlefont = f
)
margin <- list(l = 50, r=50, b=100, 
               t=100, pad=4)


fig_group <- plot_ly(
  type = 'scatter',
  x = ~transcript$Sr..No.,
  y = ~transcript$Emotion,
  text = paste("Make: ", rownames(transcript),
               "<br>Time (instances): ", transcript$Sr..No.,
               "<br>Emotion: ", transcript$Emotion,
               "<br>Anger: ", transcript$Anger),
  hoverinfo = 'text',
  mode = 'markers',
  transforms = list(
    list(
      type = 'groupby',
      groups = transcript$Emotion,
      styles = list(
        list(target = 2, value = list(marker =list(color = 'green'))),
        list(target = 4, value = list(marker =list(color = 'blue'))),
        list(target = 6, value = list(marker =list(color = 'red'))),
        list(target = 8, value = list(marker =list(color = 'white')))
      )
      )
    )
  )
fig_group <- fig_group %>% layout(title = "OpenFace Emotion Classification",
                                  font = titleFont, xaxis = x, yaxis = y,
                                  margin = margin,
                                  plot_bgcolor = "black",
                                  paper_bgcolor = "black",
                                  autosize = FALSE,
                                  width = 1000,
                                  height = 1000
                                  )
fig_group
par(mfcol = c(2,3), cex = 1)
plot(transcript$Sr..No., transcript$Anger, type = "l", 
     xlab = "Time (instances)", ylab = "Anger")
plot(transcript$Sr..No., transcript$Bored, type = "l", 
     xlab = "Time (instances)", ylab = "Bored")
plot(transcript$Sr..No., transcript$Excited, type = "l", 
     xlab = "Time (instances)", ylab = "Excited")
plot(transcript$Sr..No., transcript$Fear, type = "l", 
     xlab = "Time (instances)", ylab = "Fear")
plot(transcript$Sr..No., transcript$Happy, type = "l", 
     xlab = "Time (instances)", ylab = "Happy")
plot(transcript$Sr..No., transcript$Sad, type = "l", 
     xlab = "Time (instances)", ylab = "Sad")
mtext("Emoiton Classification (all channels)", side = 3, line = -1, outer = TRUE)

par(mfrow=c(1,1))

f <- list(
  family = "Courier New, monospace",
  size = 16,
  color = "#7f7f7f"
)
titleFont <- list(
  family = "Courier New, monospace",
  size = 18,
  color = "#7f7f7f"
)
x <- list(
  title = "Time (instances)",
  titlefont = f
)
y <- list(
  title = "Probability",
  range = c(0,1),
  titlefont = f
)
margin <- list(l = 50, r=50, b=100, 
               t=100, pad=4)
#y <- list(
#  title = "Probability",
#  titlefont = f,
#  max = 1
#)


fig1 <- plot_ly(transcript, x = ~transcript$Sr..No., y = ~transcript$Anger)
fig1 <- fig1 %>% add_lines(name = ~"Anger")
fig1 <- fig1 %>% layout(yaxis = list(range(c(0,1))))
fig2 <- plot_ly(transcript, x = ~transcript$Sr..No., y = ~transcript$Bored)
fig2 <- fig2 %>% add_lines(name = ~"Bored")
fig2 <- fig2 %>% layout(yaxis = list(range(c(0,1))))
fig3 <- plot_ly(transcript, x = ~transcript$Sr..No., y = ~transcript$Excited)
fig3 <- fig3 %>% add_lines(name = ~"Excited")
fig3 <- fig3 %>% layout(yaxis = list(range(c(0,1))))
fig4 <- plot_ly(transcript, x = ~transcript$Sr..No., y = ~transcript$Fear)
fig4 <- fig4 %>% add_lines(name = ~"Fear")
fig4 <- fig4 %>% layout(yaxis = list(range(c(0,1))))
fig5 <- plot_ly(transcript, x = ~transcript$Sr..No., y = ~transcript$Happy)
fig5 <- fig5 %>% add_lines(name = ~"Happy")
fig6 <- plot_ly(transcript, x = ~transcript$Sr..No., y = ~transcript$Sad)
fig6 <- fig6 %>% add_lines(name = ~"Sad")
fig_group2 <- subplot(fig1, fig2, fig3, fig4, fig5, fig6, nrows = 6, shareX = TRUE)
#fig_group2 <- plot_ly(width = 1000, height = 1000)
fig_group2 <- fig_group2 %>% layout(xaxis = x,
                                    yaxis = y,
                                    title = "Emotion Classification (all channels)",
                                    font = titleFont,
                                    plot_bgcolor = "black",
                                    paper_bgcolor = "black",
                                    autosize = FALSE,
                                    width = 1000,
                                    height = 1000,
                                    margin = margin
                                    )
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
#fig_group2 <- fig_group2 %>% subplot(nrows = 6, shareX = TRUE)

fig_group2
fig1

#angerMean1 = mean(transcript$anger)

#box_group <- plot_ly(transcript$Anger, y = ~transcript$Sr..No., color = ~cut, type = "box")

#box_group

heat_group <- plot_ly(transcript, x = ~log(transcript$Sr..No.), y = ~log(transcript$Anger))
subplot(
  add_histogram2d(heat_group) %>%
    colorbar(title = "default") %>%
    layout(xaxis = list(title = "default")),
  add_histogram2d(heat_group, zsmooth = "best") %>%
    colorbar(title = "zsmooth") %>%
    layout(xaxis = list(title = "zsmooth")),
  add_histogram2d(heat_group, nbinsx = 60, nbinsy = 60) %>%
    colorbar(title = "nbins") %>%
    layout(xaxis = list(title = "nbins")),
  shareY = TRUE, titleX = TRUE
)